package className;

public class ClassUtils
{

    /**
     * 获取调用的类名
     *
     * @return String
     */
    public static String getClassName()
    {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement e = stacktrace[2];
        String className = e.getClassName();
        return className;
    }

    /**
     * 获取调用的方法名
     *
     * @return String
     */
    public static String getMethodName()
    {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement e = stacktrace[2];
        String methodName = e.getMethodName();
        return methodName;
    }

    public static String getFileName()
    {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement e = stacktrace[2];
        String methodName = e.getFileName();
        return methodName;
    }

    public static int getLineNumber()
    {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement e = stacktrace[2];
        int line = e.getLineNumber();
        return line;
    }

    public static void main(String[] args)
    {


        System.out.println("当前运行的类：" + getClassName());
        System.out.println("当前执行的方法：" + getMethodName());
        System.out.println("当前文件名：" + getFileName());
        System.out.println("当前执行的行数：" + getLineNumber());

        new Thread(() -> System.out.println("wudi")).start();
        //java获取CPU的数量
        System.out.println(Runtime.getRuntime().availableProcessors());
        new Thread(() -> System.out.println("wudi2")).start();

    }
}


